<ui:composition template="/WEB-INF/template/template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:fn="http://java.sun.com/jsp/jstl/functions"
                xmlns:sgbd="http://java.sun.com/jsf/composite/components">

    <ui:define name="title">Comptes</ui:define>

    <ui:define name="navigator">
        <sgbd:navigator comptes="active" />
    </ui:define>

    <ui:define name="content">
        <h:form>
            <h2>Connexion Oracle</h2>
            <h:outputText value="Base #{compteBean.current.name}" />
            <h:commandLink action="#{oracleConnect.deconnectFromWeb()}">
                <h:graphicImage library="images" name="disconnect.gif" alt="Déconnexion" />
            </h:commandLink>
            <br /><br />

            <rich:panel header="Développeur">
                <rich:tabPanel switchType="client">
                    <rich:tab header="Sauvegarde">
                        <h3>Sauvegarde à chaud de la base de données</h3>
                        <br />
                        <rich:message for="backupHotPath" ajaxRendered="true" />
                        <h:outputText value="Chemin où sauvegarder les fichiers " />
                        <h:inputText value="#{oracleConnect.backupHotPath}"
                                     required="true"
                                     id="backupHotPath"
                                     requiredMessage="Veuillez indiquer un chemin de sauvegarde des fichiers" />
                        <h:commandLink action="#{oracleConnect.executeHotBackup()}">
                            <h:graphicImage library="images"
                                            height="16"
                                            width="16"
                                            name="Play1Pressed.png" />                            
                        </h:commandLink>
                        <h:commandLink action="#{oracleConnect.saveBackupHotScript()}">
                            <h:graphicImage library="images"
                                            name="save.png" />
                        </h:commandLink>
                    </rich:tab>
                    <rich:tab header="Mes objets">
                        <h3>Mes objets</h3>
                        <rich:dataTable value="#{oracleConnect.allObjectForCurrentUser}" 
                                        var="objectForCurrentUser"
                                        rowClasses="even,odd"
                                        styleClass="dataTable">
                            <f:facet name="header">
                                <rich:columnGroup>
                                    <rich:column colspan="1">
                                        <h:outputText value="Objets" />
                                    </rich:column>
                                    <rich:column breakRowBefore="true">
                                        <h:outputText value="Nom" />
                                    </rich:column>
                                </rich:columnGroup>
                            </f:facet>
                            <rich:column colspan="1">
                                <rich:collapsibleSubTableToggler for="myOracleObject" />
                                <h:outputText value="#{objectForCurrentUser.type}" />
                            </rich:column>
                            <rich:collapsibleSubTable value="#{objectForCurrentUser.listObject}"
                                                      var="myOracleObject"
                                                      expanded="#{false}"
                                                      id="myOracleObject"                                          
                                                      expandMode="client">
                                <rich:column>
                                    <h:outputText value="#{myOracleObject}" />
                                </rich:column>
                                <f:facet name="footer">
                                    <h:outputText value="Total : #{objectForCurrentUser.count}" />
                                </f:facet>
                            </rich:collapsibleSubTable>
                        </rich:dataTable>
                    </rich:tab>
                    <rich:tab header="Mes tables">
                        <h3>Mes tables et index</h3>
                        <rich:dataTable value="#{oracleConnect.allTableOracleForCurrentUser}" 
                                        var="tableOracleForCurrentUser"
                                        rowClasses="even,odd"
                                        styleClass="dataTable">
                            <f:facet name="header">
                                <rich:columnGroup>
                                    <rich:column colspan="6">
                                        <h:outputText value="Tables" />
                                    </rich:column>
                                    <rich:column breakRowBefore="true">
                                        <h:outputText value="Nom" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Type" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Table owner" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Table type" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="Tablespace name" />
                                    </rich:column>
                                    <rich:column>
                                        <h:outputText value="PctFree" />
                                    </rich:column>
                                </rich:columnGroup>
                            </f:facet>
                            <rich:column colspan="6">
                                <rich:collapsibleSubTableToggler for="indexByTableOracle" />
                                <h:outputText value="#{tableOracleForCurrentUser.name}" />
                            </rich:column>
                            <rich:collapsibleSubTable value="#{tableOracleForCurrentUser.indexes}"
                                                      var="indexByTableOracle"
                                                      expanded="#{false}"
                                                      id="indexByTableOracle"                                          
                                                      expandMode="client">
                                <rich:column>
                                    <h:outputText value="#{indexByTableOracle.name}" />
                                </rich:column>
                                <rich:column>
                                    <h:outputText value="#{indexByTableOracle.type}" />
                                </rich:column>
                                <rich:column>
                                    <h:outputText value="#{indexByTableOracle.tableOwner}" />
                                </rich:column>
                                <rich:column>
                                    <h:outputText value="#{indexByTableOracle.tableType}" />
                                </rich:column>
                                <rich:column>
                                    <h:outputText value="#{indexByTableOracle.tableSpaceName}" />
                                </rich:column>
                                <rich:column>
                                    <h:outputText value="#{indexByTableOracle.pctFree}" />
                                </rich:column>
                                <f:facet name="footer">
                                    <h:outputText value="Total : #{fn:length(tableOracleForCurrentUser.indexes)}" />
                                </f:facet>
                            </rich:collapsibleSubTable>
                        </rich:dataTable>
                        <br />
                        <h3>Mes tables et commande de mise en place</h3>
                        <rich:dataTable value="#{oracleConnect.allTableOracleForCurrentUser}"
                                        var="tableOracleCommandForCurrentUser"
                                        styleClass="dataTable"
                                        rowClasses="even,odd">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{tableOracleCommandForCurrentUser.name}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Commande de mise en place de la table" />
                                </f:facet>
                                <h:outputText value="#{tableOracleCommandForCurrentUser.command}" />
                            </rich:column>
                            <rich:column>
                                <h:commandLink action="#{oracleConnect.saveCommandTable()}">

                                    <f:setPropertyActionListener target="#{oracleConnect.currentTable}" 
                                                                 value="#{tableOracleCommandForCurrentUser}" />
                                    <h:graphicImage library="images"
                                                    name="save.png" />
                                </h:commandLink>

                            </rich:column>
                        </rich:dataTable>
                    </rich:tab>
                    <rich:tab header="Mes vues">
                        <h3>Mes Vues</h3>
                        <rich:dataTable value="#{oracleConnect.allViewOracleForCurrentUser}"
                                        var="viewOracleCurrentUser"
                                        styleClass="dataTable"
                                        rowClasses="even,odd">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{viewOracleCurrentUser.name}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Commande" />
                                </f:facet>
                                <h:outputText value="#{viewOracleCurrentUser.command}" />
                            </rich:column>
                            <rich:column>
                                <h:commandLink action="#{oracleConnect.saveCommandView()}">

                                    <f:setPropertyActionListener target="#{oracleConnect.currentView}" 
                                                                 value="#{viewOracleCurrentUser}" />
                                    <h:graphicImage library="images"
                                                    name="save.png" />
                                </h:commandLink>

                            </rich:column>                        
                        </rich:dataTable> 
                    </rich:tab>
                    <rich:tab header="Mes méthodes">
                        <h3>Mes méthodes</h3>
                        <rich:dataTable value="#{oracleConnect.allMethodeOracleForCurrentUser}"
                                        var="methodeOracleCurrentUser"
                                        styleClass="dataTable"
                                        rowClasses="even,odd">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{methodeOracleCurrentUser.name}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Type" />
                                </f:facet>
                                <h:outputText value="#{methodeOracleCurrentUser.type}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Text" />
                                </f:facet>
                                <h:outputText value="#{methodeOracleCurrentUser.content}" escape="false" />
                            </rich:column>
                            <rich:column>
                                <h:commandLink action="#{oracleConnect.saveContentMethode()}">

                                    <f:setPropertyActionListener target="#{oracleConnect.currentMethode}" 
                                                                 value="#{methodeOracleCurrentUser}" />
                                    <h:graphicImage library="images"
                                                    name="save.png" />
                                </h:commandLink>

                            </rich:column>
                        </rich:dataTable>
                    </rich:tab>
                    <rich:tab header="Mes déclencheurs">
                        <h3>Mes triggers</h3>
                        <rich:dataTable value="#{oracleConnect.allTriggerOracleForCurrentUser}"
                                        var="triggerOracleCurrentUser"
                                        styleClass="dataTable"
                                        rowClasses="even,odd">
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Name" />
                                </f:facet>
                                <h:outputText value="#{triggerOracleCurrentUser.name}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Commande" />
                                </f:facet>
                                <h:outputText value="#{triggerOracleCurrentUser.command}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:outputText value="Text" />
                                </f:facet>
                                <h:outputText value="#{triggerOracleCurrentUser.content}" escape="false" />
                            </rich:column>
                            <rich:column>
                                <h:commandLink action="#{oracleConnect.saveCommandTrigger()}">

                                    <f:setPropertyActionListener target="#{oracleConnect.currentTrigger}" 
                                                                 value="#{triggerOracleCurrentUser}" />
                                    <h:graphicImage library="images"
                                                    name="save.png" />
                                </h:commandLink>

                            </rich:column>
                        </rich:dataTable> 
                    </rich:tab>
                    <rich:tab header="Plan d'exécution">
                        <h3>Plan d'éxecution</h3>
                        <h:panelGrid columns="4">
                            <h:inputTextarea cols="100" rows="10" value="#{oracleConnect.myQuery}"/>
                            <a4j:commandButton action="#{oracleConnect.createExecutionPlan()}" 
                                               value="OK"
                                               render="explainPlan saveExplainPlan"/>                    
                            <h:outputText id="explainPlan" value="#{oracleConnect.executionPlan}" escape="false" />
                            <a4j:outputPanel ajaxRendered="true">
                                <h:commandLink action="#{oracleConnect.saveExecutionPlan()}"
                                               rendered="#{not empty oracleConnect.myQuery}"
                                               id="saveExplainPlan">
                                    <h:graphicImage library="images"
                                                    name="save.png" />
                                </h:commandLink>
                            </a4j:outputPanel>
                        </h:panelGrid>
                    </rich:tab>
                </rich:tabPanel>                
            </rich:panel>
        </h:form>
    </ui:define>
</ui:composition>